package com.mico.example.springboot.mybatis.multi.service.impl;




import com.mico.example.springboot.mybatis.multi.dao.primary.UserMapper;
import com.mico.example.springboot.mybatis.multi.dao.secondary.CityMapper;
import com.mico.example.springboot.mybatis.multi.domain.primary.User;
import com.mico.example.springboot.mybatis.multi.domain.secondary.City;
import com.mico.example.springboot.mybatis.multi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by micocube
 * ProjectName: springboot-example
 * PackageName: com.mico.example.springboot.jpa.service.impl
 * User: micocube
 * Email: ldscube@gmail.com
 * CreateTime: 2019/2/25下午1:52
 * ModifyTime: 2019/2/25下午1:52
 * Version: 0.1
 * Description:
 **/
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userDao;
    @Autowired
    CityMapper cityMapper;

    @Override
    public User findById(Integer id){
        User user = userDao.selectByPrimaryKey(id);
        City city = cityMapper.selectByPrimaryKey(1);
        user.setCity(city);
        return user;
    }

    @Override
    public int testTransaction() {
        User record = new User();
        record.setEmail("ldscube@gmail.com");
        record.setUsername("multiDatasource");
        record.setPassword("123456");
        record.setEnabled(true);
        record.setNickname("pwd");
        int insert = userDao.insert(record);
        City city = new City();
        city.setCity("重庆");
        city.setProvince("四川");
        cityMapper.insert(city);
        System.out.println(1/0);
        return insert;
    }

}
